<template>
  <div style="height: 785px;">

    <el-row :gutter="0"
            style="background:white;border-bottom: 1px solid #CCCCCC;margin: -20px;text-align: left;height: 40px;line-height: 40px">
      <el-col :span="24" :offset="0">
        <el-button type="text" @click="goback" style="color: black"><i class="el-icon-arrow-left"></i>&nbsp;&nbsp;提升额度
        </el-button>
      </el-col>
    </el-row>

    <el-card class="box-card" style="background: white;margin-top: 40px;"><!--#336699-->
      <div style="margin-top: 15px;">目前总额度（元）</div>
      <div style="margin-top: 25px;margin-bottom: 35px;font-size:50px;">{{money1}}</div>
    </el-card>


    <el-collapse accordion style="margin-top: 20px;">
      <el-collapse-item>
        <template slot="title">
          完善毕业证信息<i class="header-icon el-icon-info"></i>
        </template>

        <el-form ref="form" :model="form" label-width="80px" style="margin-top: 20px;padding-right: 20px;">
          <el-upload
            class="avatar-uploader"
            action="http://localhost:9999/credit-borrower/upload"
            :show-file-list="false"
            :on-success="handleAvatarSuccessthree"
            :before-upload="beforeAvatarUpload"
          >
            <img v-if="imageUrl2" :src="imageUrl2" class="avatar" style="width:5px; height: 5px;background-color: coral">
            <i v-else class="el-icon-plus avatar-uploader-icon"></i>
          </el-upload>
          <!--图片-->
          <el-form-item label="证件证明照片">
            <el-image
              style="width: 100px; height: 100px"
              :src="form.certificatePhoto"
              fit="fit"></el-image>
          </el-form-item>

          <el-form-item style="margin-top: 20px">
            <el-button type="primary" @click="onSubmit('学位证')">立即添加</el-button>
            <el-button @click="goback">取消</el-button>
          </el-form-item>
        </el-form>
        <div>
          <ul>
            <div v-for="(o,index) in tableData" style="float: left;margin-left: 2px">
              <el-image
                v-if="o.certificateName=='学位证'"
                style="width: 100px; height: 100px"
                :src="o.certificatePhoto"
                fit="fit"></el-image>
            </div>
          </ul>
        </div>
      </el-collapse-item>
    </el-collapse>

    <el-collapse accordion style="margin-top: 20px;">
      <el-collapse-item>
        <template slot="title">
          完善驾驶证信息<i class="header-icon el-icon-info"></i>
        </template>

        <el-form ref="form" :model="form" label-width="80px" style="margin-top: 20px;padding-right: 20px;">
          <el-upload
            class="avatar-uploader"
            action="http://localhost:9999/credit-borrower/upload"
            :show-file-list="false"
            :on-success="handleAvatarSuccesstow"
            :before-upload="beforeAvatarUpload"
          >
            <img v-if="imageUrl1" :src="imageUrl1" class="avatar" style="width:5px; height: 5px;background-color: coral">
            <i v-else class="el-icon-plus avatar-uploader-icon"></i>
          </el-upload>

          <!--图片-->
          <el-form-item label="证件证明照片">
            <el-image
              style="width: 100px; height: 100px"
              :src="form.certificatePhoto"
              fit="fit"></el-image>
          </el-form-item>
          <el-form-item style="margin-top: 20px">
            <el-button type="primary" @click="onSubmit('驾驶证')">立即添加</el-button>
            <el-button @click="goback">取消</el-button>
          </el-form-item>
        </el-form>
        <div>
          <ul>
            <div v-for="(o,index) in tableData" style="float: left;margin-left: 2px">
              <el-image
                v-if="o.certificateName=='驾驶证'"
                style="width: 100px; height: 100px"
                :src="o.certificatePhoto"
                fit="fit"></el-image>
            </div>
          </ul>
        </div>
      </el-collapse-item>
    </el-collapse>

    <el-collapse accordion style="margin-top: 20px;">
      <el-collapse-item>
        <template slot="title">
          完善房产证信息<i class="header-icon el-icon-info"></i>
        </template>

        <el-form ref="form" :model="form" label-width="80px" style="margin-top: 20px;padding-right: 20px;">
          <!--    <el-upload
                class="upload-demo"
                action="https://jsonplaceholder.typicode.com/posts/"
                :on-preview="handlePreview"
                :on-remove="handleRemove"
                :file-list="fileList"
                list-type="picture">
                <el-button size="small" type="primary">点击上传</el-button>
                <div slot="tip" class="el-upload__tip">只能上传jpg/png文件，且不超过500kb</div>
              </el-upload>-->

          <el-upload
            class="avatar-uploader"
            action="http://localhost:9999/credit-borrower/upload"
            :show-file-list="false"
            :on-success="handleAvatarSuccess"
            :before-upload="beforeAvatarUpload"
          >
            <img v-if="imageUrl" :src="imageUrl" class="avatar" style="width:5px; height: 5px;background-color: coral">
            <i v-else class="el-icon-plus avatar-uploader-icon"></i>
          </el-upload>

          <!--图片-->
          <el-form-item label="证件证明照片">
            <el-image
              style="width: 100px; height: 100px"
              :src="form.certificatePhoto"
              fit="fit"></el-image>
          </el-form-item>
          <el-form-item style="margin-top: 20px">
            <el-button type="primary" @click="onSubmit('房产证')">立即添加</el-button>
            <el-button @click="goback">取消</el-button>
          </el-form-item>
        </el-form>
        <div>
          <ul>
            <div v-for="(o,index) in tableData" style="float: left;margin-left: 2px">
              <el-image
                v-if="o.certificateName=='房产证'"
                style="width: 100px; height: 100px"
                :src="o.certificatePhoto"
                fit="fit"></el-image>
            </div>
          </ul>
        </div>
      </el-collapse-item>
    </el-collapse>


  </div>
</template>

<script>
  import axios from 'axios'

  export default {
    name: "increaseQuota",
    data() {
      return {
        money1: '10000.00',
        activeName: 'first',
        form: {},
        imageUrl:'',
        imageUrl1:'',
        imageUrl2:'',
        tableData:[],
      };
    },
    methods: {
      onSubmit: function (certificateName) {
        this.form.certificateName=certificateName;
        axios.post("http://localhost:9999/credit-borrower/saveOrUpdateByBorrowerId",this.form).then(res => {
          if(res.data=="success"){
            alert("上传成功")
          }
        })
      },

      goback: function () {
        this.$router.push("/borrow")
      },
      myQuotaDetail: function () {
        this.$router.push("/myQuotaDetail")
      },
      fun1: function () {
        this.$router.push("/borrowReal")
      },
      fun2: function () {
        this.$router.push("/borrowRecord")
      },


      /*   handleRemove(file, fileList) {
           console.log(file, fileList);
         },
         handlePreview(file) {
           console.log(file);
         },*/

      handleAvatarSuccess(res, file) {
        this.form.certificatePhoto = res;
        this.imageUrl = URL.createObjectURL(file.raw);
      },
      handleAvatarSuccesstow(res, file) {
        this.form.certificatePhoto = res;
        this.imageUrl1 = URL.createObjectURL(file.raw);
      },
      handleAvatarSuccessthree(res, file) {
        this.form.certificatePhoto = res;
        this.imageUrl2 = URL.createObjectURL(file.raw);
      },
      beforeAvatarUpload(file) {
        const isJPG = file.type === 'image/jpeg';
        const isLt2M = file.size / 1024 / 1024 < 2;

        if (!isJPG) {
          this.$message.error('上传头像图片只能是 JPG 格式!');
        }
        if (!isLt2M) {
          this.$message.error('上传头像图片大小不能超过 2MB!');
        }
        return isJPG && isLt2M;
      },
      findall(){
        axios.post("http://localhost:9999/credit-borrower/findByBorrowerId").then(res => {
          this.tableData=res.data;
          console.log(res.data);
        })
      }
    },



    mounted(){
      this.findall();
    }
  }
</script>

<style scoped>
  .avatar-uploader .el-upload {
    border: 1px dashed #d9d9d9;
    border-radius: 6px;
    cursor: pointer;
    position: relative;
    overflow: hidden;
  }
  .avatar-uploader .el-upload:hover {
    border-color: #409EFF;
  }
  .avatar-uploader-icon {
    font-size: 28px;
    color: #8c939d;
    width: 178px;
    height: 178px;
    line-height: 178px;
    text-align: center;
  }
  .avatar {
    width: 100px;
    height: 100px;
    display: block;
  }
</style>
